home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / glob.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  3KB  |  100 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. '''Filename globbing utility.'''
  5. import sys
  6. import os
  7. import re
  8. import fnmatch
  9.  
  10. try:
  11.     _unicode = unicode
  12. except NameError:
  13.     
  14.     class _unicode(object):
  15.         pass
  16.  
  17.  
  18. __all__ = [
  19.     'glob',
  20.     'iglob']
  21.  
  22. def glob(pathname):
  23.     """Return a list of paths matching a pathname pattern.
  24.  
  25.     The pattern may contain simple shell-style wildcards a la
  26.     fnmatch. However, unlike fnmatch, filenames starting with a
  27.     dot are special cases that are not matched by '*' and '?'
  28.     patterns.
  29.  
  30.     """
  31.     return list(iglob(pathname))
  32.  
  33.  
  34. def iglob(pathname):
  35.     """Return an iterator which yields the paths matching a pathname pattern.
  36.  
  37.     The pattern may contain simple shell-style wildcards a la
  38.     fnmatch. However, unlike fnmatch, filenames starting with a
  39.     dot are special cases that are not matched by '*' and '?'
  40.     patterns.
  41.  
  42.     """
  43.     if not has_magic(pathname):
  44.         if os.path.lexists(pathname):
  45.             yield pathname
  46.         return None
  47.     (dirname, basename) = None.path.split(pathname)
  48.     if not dirname:
  49.         for name in glob1(os.curdir, basename):
  50.             yield name
  51.         
  52.         return None
  53.     if None != pathname and has_magic(dirname):
  54.         dirs = iglob(dirname)
  55.     else:
  56.         dirs = [
  57.             dirname]
  58.     if has_magic(basename):
  59.         glob_in_dir = glob1
  60.     else:
  61.         glob_in_dir = glob0
  62.     for dirname in dirs:
  63.         for name in glob_in_dir(dirname, basename):
  64.             yield os.path.join(dirname, name)
  65.         
  66.     
  67.  
  68.  
  69. def glob1(dirname, pattern):
  70.     if not dirname:
  71.         dirname = os.curdir
  72.     if isinstance(pattern, _unicode) and not isinstance(dirname, unicode):
  73.         if not sys.getfilesystemencoding():
  74.             pass
  75.         dirname = unicode(dirname, sys.getdefaultencoding())
  76.     
  77.     try:
  78.         names = os.listdir(dirname)
  79.     except os.error:
  80.         return []
  81.  
  82.     if pattern[0] != '.':
  83.         names = filter((lambda x: x[0] != '.'), names)
  84.     return fnmatch.filter(names, pattern)
  85.  
  86.  
  87. def glob0(dirname, basename):
  88.     if basename == '' or os.path.isdir(dirname):
  89.         return [
  90.             basename]
  91.     if os.path.lexists(os.path.join(dirname, basename)):
  92.         return [
  93.             basename]
  94.  
  95. magic_check = re.compile('[*?[]')
  96.  
  97. def has_magic(s):
  98.     return magic_check.search(s) is not None
  99.  
  100.